// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
//
// $Id: xpath.hpp 210 2008-08-28 10:10:41Z heavyzheng $
//

#ifndef ZZHENG_XML_DOM_LIBXML2_XPATH_HPP_20080722__
#define ZZHENG_XML_DOM_LIBXML2_XPATH_HPP_20080722__

#include <zzheng/xml/config.hpp>
#include <zzheng/xml/dom/libxml2/xpath_result.hpp>
#include <zzheng/xml/dom/libxml2/libxml2_fwd.hpp>

#include <string>
#include <map>

namespace zzheng {
namespace xml {
namespace dom {
namespace libxml2_ {

    class node;
    class document;

    //! This class represents an XPath expression.
    class xpath {

        typedef std::map<std::string, std::string> namespace_map;

    public:

        void add_namespace(const std::string& uri, const std::string& prefix);

        //! Evaluates an XPath expression and returns the result.
        //! \param expr  the XPath expression to evaluate.
        //! \param nd    the XML node from which the expression is to be evaluated.
        //! \return an XPath result object.
        xpath_result evaluate(const std::string& expr, node& nd) const;

        //! Evaluates an XPath expression and returns the result.
        //! \param expr  the XPath expression to evaluate.
        //! \param doc   the XML document on which the expression is to be evaluated.
        //! \return an XPath result object.
        xpath_result evaluate(const std::string& expr, document& doc) const;

        //! Evaluates an XPath expression and returns the result.
        //! \param expr    the XPath expression to evaluate.
        //! \param nd      the XML node from which the expression is to be evaluated.
        //! \param result  output parameter to hold the XPath result.
        void evaluate(const std::string& expr, node& nd, xpath_result& result) const;

        //! Evaluates an XPath expression and returns the result.
        //! \param expr    the XPath expression to evaluate.
        //! \param doc     the XML document on which the expression is to be evaluated.
        //! \param result  output parameter to hold the XPath result.
        void evaluate(const std::string& expr, document& doc, xpath_result& result) const;

    private:

        void evaluate_(const std::string& expr,
                       xmlDoc* px_doc,
                       xmlNode* px_node,
                       xpath_result& result) const;

    private:

        namespace_map namespaces_; //!< Added namespaces: key is prefix, value is URI.

    }; // class xpath

} // namespace zzheng::xml::dom::libxml2_
} // namespace zzheng::xml::dom
} // namespace zzheng::xml
} // namespace zzheng


#endif // ZZHENG_XML_DOM_LIBXML2_XPATH_HPP_20080722__



